package cn.tedu.v1_1;

import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

/**
 * 聊天室Version1.1   【写软件没有顺序--只有业务逻辑】
 * 功能：服务器端启动【申请：端口号】--客户端连接服务器【IP+端口】
 * 完成哪些功能：
 * 1.客户端：私有化Socket通讯
 * 2.客户端：构造器中：传入IP并且指定端口号【捕获所有异常，创建时候异常
 *                                                运行时候的异常
 *  】
 *
 * 新增哪些内容：异常明确化
 *
 */

public class Client {
     private Socket socket;

    public Client() {
        try{
            socket=new Socket("127.0.0.1",5656);
        } catch (UnknownHostException e){
            System.out.println("友情提示：IP传入出错");
        } catch (IOException e){
             System.out.println("客户端连接服务器失败，提示：检查IP/端口");
        }
    }
    public void start() throws IOException {
        OutputStream os =socket.getOutputStream();
       // InputStream is=socket.getInputStream();
        OutputStreamWriter osw=new OutputStreamWriter(os,"UTF8");
      //  InputStreamReader isr=new InputStreamReader(is);
        BufferedWriter bw=new BufferedWriter(osw);
      //  BufferedReader br=new BufferedReader(isr);
         PrintWriter pw=new PrintWriter(bw,true);
         System.out.println("请对李佳怡说话：");
         Scanner input=new Scanner(System.in);
        String line=null;
         while(true){
            line =input.nextLine();
            pw.println(line);
            System.out.println("好的");
        }
    }
     public static void main(String[] args) throws IOException {
        Client client=new Client();
        client.start();
    }
}